﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mengoo.BDMTier;
using Mammoo.WebServer.Model;
using Mengoo.DB;
using System.Data;

namespace Mammoo.WebServer.DAL
{
    public class MemberDao:DAO
    {
        /// <summary>
        /// 实例化
        /// </summary>
        public MemberDao()
        {
            tableName = "member";
            keyField = "member_id";
        }

        /// <summary>
        /// 实例化
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="keyField"></param>
        /// <param name="connectionType"></param>
        public MemberDao(string tableName, string keyField, string connectionType)
        {
            this.tableName = tableName;
            this.keyField = keyField;
            this.connectionType = connectionType;
        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public MemberInfo Login(string username, string password)
        {
            List<string> whereList = new List<string>();
            whereList.Add(SqlAdapt.AdaptEquals("member_username", username));
            whereList.Add(SqlAdapt.AdaptEquals("member_password", password));

            MemberInfo model = GetModel<MemberInfo>(SqlAdapt.AdaptAnd(whereList), "*");

            return model;
        }

        public DataTable GetMemberID(string username, string email)
        {
            List<string> whereList = new List<string>();            
            if (!string.IsNullOrEmpty(username))
            {
                whereList.Add(SqlAdapt.AdaptEquals("member_username", username));
            }

            if (!string.IsNullOrEmpty(email))
            {
                whereList.Add(SqlAdapt.AdaptEquals("member_email", email));
            }

            return GetTableList("Member_ID", SqlAdapt.AdaptAnd(whereList));
        }
    }
}
